package mollmapsgenerator;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author hanis
 */
public class Record implements Comparable {

    public static final String THUMBNAIL_SUFFIX = "preview.jpg";
    public static final String IMAGESERVER_ULR = "imageserver.mzk.cz";
    
    private String oldSignature;
    private String newSignatre;
    private String sysno;
    private String name; //245 a

    private String CollectionSignature = "";

    private String numberOfPart; // 245 n
    private String nameOfPart; // 245 p
    private String authorName; // 100 a
    private String authorDate; // 100 d

    private String publicationPlace; //260 a
    private String publicationName;//260 a
    private String publicationDate;//260 a

    private String colectionURL = "";

    

    private boolean supplemented;

    
//    private String personalName; //100 a
//    private String dates; //100 d
//
//    private String addedPersonalName; //700 a
//    private String addedDates; //700 d


//    private String title; //245 a




    private String parentSysno;
    private List<String> urlList;
    private boolean parent = false;


    
    public Record() {
        
    }

    public Record(String sysno) {
        this.sysno = sysno;
    }

    public String getOldSignature() {
        return oldSignature;
    }

    public void setOldSignature(String signature) {
        this.oldSignature = signature;
    }

    public String getSysno() {
        return sysno;
    }

    public void setSysno(String sysno) {
        this.sysno = sysno;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }


    public int getSignatureNumber() {
        String number = oldSignature.substring(oldSignature.lastIndexOf(",")+1);
        return Integer.valueOf(number);
    }

    public String getNewSignatre() {
        return newSignatre;
    }

    public void setNewSignatre(String newSignatre) {
        this.newSignatre = newSignatre;
    }




    @Override
    public String toString() {
        String s = "sysno: " + getSysno() + ", signature: " + getOldSignature() + ", name: " + getName();
        if(hasParent()) {
            s += "\n       - parent: " + getParentSysno();
        }
        return s;
    }

    public String getParentSysno() {
        return parentSysno;
    }

    public void setParentSysno(String parentSysno) {
        this.parent = true;
        this.parentSysno = "00" + parentSysno;
    }

    public boolean hasParent() {
        return parent;
    }


    @Override
    public boolean equals(Object obj) {
        if(obj == null) {
            return false;
        }
        if(obj instanceof Record) {
            Record r = (Record) obj;
            if(r.getSysno().equals(getSysno())) {
                return true;
            }
        }
        return false;

    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 29 * hash + (this.sysno != null ? this.sysno.hashCode() : 0);
        return hash;
    }




    public int compareTo(Object o) {
        Record record = (Record) o;
        return getNewSignatre().compareTo(record.getNewSignatre());
//        if(this.getSignatureNumber() < thumb.getSignatureNumber()) {
//            return -1;
//        }
//        return +1;


    }




    public List<String> getUrlList() {
        if(urlList == null) {
            return Collections.<String>emptyList();
        }
        return urlList;
    }


    public void setUrlList(List<String> urlList) {
        this.urlList = urlList;
    }

    public void addUrl(String url) {
        if(urlList == null) {
            urlList = new ArrayList<String>();
        }
        this.urlList.add(url);
    }


    public void removeNonImageserverLinks() {
        List<String> newUrlList = new ArrayList<String>();
        for (String url : urlList) {
            if(url.contains(IMAGESERVER_ULR)) {
                newUrlList.add(url);
            }
        }
        setUrlList(newUrlList);
    }



    public List<String> getThumbnailUrlList() {
        List<String> thumbnailList = new ArrayList<String>();
        for (String url : getUrlList()) {
            thumbnailList.add(getThumbnail(url));
        }
        return thumbnailList;
    }


    public String getThumbnail(String url) {
        return url + "/" + THUMBNAIL_SUFFIX;
    }




    public boolean isSupplemented() {
        return supplemented;
    }


    public void setSupplemented(boolean supplemented) {
        this.supplemented = supplemented;
    }

    /**
     * @return the nameOfPart
     */
    public String getNameOfPart() {
        return nameOfPart;
    }

    /**
     * @param nameOfPart the nameOfPart to set
     */
    public void setNameOfPart(String nameOfPart) {
        this.nameOfPart = nameOfPart;
    }

    /**
     * @return the authorName
     */
    public String getAuthorName() {
        return authorName;
    }

    /**
     * @param authorName the authorName to set
     */
    public void setAuthorName(String authorName) {
        this.authorName = authorName;
    }

    /**
     * @return the authorDate
     */
    public String getAuthorDate() {
        return authorDate;
    }

    /**
     * @param authorDate the authorDate to set
     */
    public void setAuthorDate(String authorDate) {
        this.authorDate = authorDate;
    }

    /**
     * @return the publicationPlace
     */
    public String getPublicationPlace() {
        return publicationPlace;
    }

    /**
     * @param publicationPlace the publicationPlace to set
     */
    public void setPublicationPlace(String publicationPlace) {
        this.publicationPlace = publicationPlace;
    }

    /**
     * @return the publicationName
     */
    public String getPublicationName() {
        return publicationName;
    }

    /**
     * @param publicationName the publicationName to set
     */
    public void setPublicationName(String publicationName) {
        this.publicationName = publicationName;
    }

    /**
     * @return the publicationDate
     */
    public String getPublicationDate() {
        return publicationDate;
    }

    /**
     * @param publicationDate the publicationDate to set
     */
    public void setPublicationDate(String publicationDate) {
        this.publicationDate = publicationDate;
    }

    public String getColectionURL() {
        return colectionURL;
    }

    public void setColectionURL(String colectionURL) {
        this.colectionURL = colectionURL;
    }

    public String getCollectionSignature() {
        return CollectionSignature;
    }

    public void setCollectionSignature(String CollectionSignature) {
        this.CollectionSignature = CollectionSignature;
    }

    public String getNumberOfPart() {
        return numberOfPart;
    }

    public void setNumberOfPart(String numberOfPart) {
        this.numberOfPart = numberOfPart;
    }



}
